<?php

class Sistema_Form_Modulos extends Zend_Form
{

    public function init()
    {
        $front = Zend_Controller_Front::getInstance();
        $controller = $front->getRequest()->getControllerName();
        $module = $front->getRequest()->getModuleName();
        $url = $front->getBaseUrl().'/'.$module.'/'.$controller;
        
        $this->setName('form_modulo');
        
        $el = new Zend_Form_Element_Hidden('MOD_ID',array('disableLoadDefaultDecorators' =>true));
        $el->addDecorators(array(array('ViewHelper'),array('Errors')))
            ->addFilter('Int');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('MOD_NOME');
        $el->setLabel('Nome')
        ->setRequired(true)
        ->addFilter('StripTags')
        ->addFilter('StringTrim')
        ->addValidator('NotEmpty');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('MOD_ARQUIVO');
        $el->setLabel('Arquivo')
        ->setRequired(true)
        ->addFilter('StripTags')
        ->addFilter('StringTrim')
        ->addValidator('NotEmpty');
        $this->addElement($el);
        
        $obj = new Sistema_Model_DbTable_Menu();
        $row = $obj->fetchAll($obj->select()->order('MEN_ORD ASC'))->toArray();
        foreach($row as $r) $arr[$r['MEN_ID']] = $r['MEN_NOME']; 
        
        $el = new Zend_Form_Element_Select('MEN_ID',array('onchange' => ''));
        $el->setLabel('Menu')
        ->setRequired(true)
        ->addFilter('StripTags')
        ->addFilter('StringTrim')
        ->addValidator('NotEmpty')
        ->addMultiOptions($arr);
        $this->addElement($el);
        
        $arr = array(
            '' => '',
            'icon_pagina'   => 'Pagina',
            'icon_up'       => 'Up',
            'icon_down'     => 'Down',
            'icon_curso'    => 'ABC',
            'icon_conta'    => 'Conta',
            'icon_galeria'  => 'Galeria',
            'icon_site'     => 'Site',
            'icon_pessoa'   => 'Pessoa',
            'icon_material' => 'Material',
            'icon_video'    => 'Vídeo',
            'icon_html'     => 'Html',
            'icon_grupo'    => 'Grupo',
            'icon_compra'       => 'Compra',
            'icon_repositorio'  => 'Repositório',
            'icon_acesso'       => 'Acesso',
            'icon_calendario'   => 'Calendario',
        );
        asort($arr);
        $el = new Zend_Form_Element_Select('MOD_ICONE',array('onchange' => ''));
        $el->setLabel('Icone')
        //->setRequired(true)
        //->addFilter('StripTags')
        //->addFilter('StringTrim')
        //->addValidator('NotEmpty')
        ->addMultiOptions($arr);
        $this->addElement($el);
        /*
        $arr = array(
            '1'   => 'Sistema',
            '2'   => 'Ead',
        );
        //asort($arr);
        $el = new Zend_Form_Element_Select('MOD_TPOSIS',array('onchange' => ''));
        $el->setLabel('Tipo de Sistema')
        ->addMultiOptions($arr);
        $this->addElement($el);
        */
        
        
        $el = new Zend_Form_Element_Checkbox('MOD_ATIVO',array('checked'=>'checked'));
        $el->setLabel('Ativo')
        ->setRequired(true)
        ->addFilter('StripTags')
        ->addFilter('StringTrim')
        ->addValidator('NotEmpty');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Checkbox('MOD_MENU',array('checked'=>'checked'));
        $el->setLabel('Mostrar Menu')
        ->setRequired(true)
        ->addFilter('StripTags')
        ->addFilter('StringTrim')
        ->addValidator('NotEmpty');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('MOD_ORDMEN');
        $el->setLabel('Ordem Menu')
        ->setRequired(true)
        ->addFilter('Int')
        ->addValidator('NotEmpty');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Checkbox('MOD_HOME',array('checked'=>'checked'));
        $el->setLabel('Mostrar Página Inicial')
        ->setRequired(true)
        ->addFilter('StripTags')
        ->addFilter('StringTrim')
        ->addValidator('NotEmpty');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('MOD_ORDMENINI');
        $el->setLabel('Ordem Página Inicial')
        ->setRequired(true)
        ->addFilter('Int')
        ->addValidator('NotEmpty');
        $this->addElement($el);
        
        $img = 'public/upload/'.$controller.'/'.$front->getRequest()->getParam('id').'.*';
        foreach (glob($img) as $src) {
            $el = new Zend_Form_Element('img',array( 'helper'=>'formNote', 'value'=>'<img src="'.$front->getBaseUrl().'/'.$src.'" />' ));
            $this->addElement($el);
        }
        
        $el = new Zend_Form_Element_File('MOD_FILE');
        $el->setLabel('Imagem - Tamanho: 70x58')
	->addValidator('Extension', false, array('jpg', 'png', 'gif'));
        $this->addElement($el);
        
        $img = 'public/upload/'.$controller.'/'.$front->getRequest()->getParam('id').'_.*';
        foreach (glob($img) as $src) {
            $el = new Zend_Form_Element('img2',array( 'helper'=>'formNote', 'value'=>'<img src="'.$front->getBaseUrl().'/'.$src.'" />' ));
            $this->addElement($el);
        }
        
        $el = new Zend_Form_Element_File('MOD_FILE2');
        $el->setLabel('Imagem Hover - Tamanho: 70x58')
	->addValidator('Extension', false, array('jpg', 'png', 'gif'));
        $this->addElement($el);
        
        $btn = new Zend_Form_Element_Submit('submit',array('disableLoadDefaultDecorators' =>true));
        $btn->addDecorators(array(array('ViewHelper'),array('Errors')));
        $btn->setAttrib('id', 'submitbutton');
        $btn->setAttrib('class', 'btn-button btn-ok');
        $this->addElement($btn);
        
        $btn = new Zend_Form_Element_Button('Cancelar',array('disableLoadDefaultDecorators' =>true));
        //$btn->addDecorators(array(array('ViewHelper'),array('Errors')));
        $btn->setDecorators(array(array('Description', array('escape' => false, 'tag' => false))));
        $btn->setDescription('<a href="'.$url.'" class="btn-button btn-cancel">Cancelar</a>');
        $btn->setAttrib('id', 'btncancel');
        $btn->setAttrib('class', 'btn-button btn-cancel');
        $this->addElement($btn);
     
    }


}

